// 导入axios实例
import httpRequest from '../request/index';
// sha256加密
import sha256 from 'crypto-js/sha256';


// 添加电视剧链接
export function addTeleplayLink(tlink) {
    tlink['time'] = Math.round(new Date().getTime() / 1000);
    let params = `${tlink.name}${tlink.url}XpFaEDYkQH`;
    tlink['sign'] = sha256(params).toString().substring(0, 15);
    return httpRequest({
        baseURL: '/admin',
        url: `/tlink/add`,
        method: 'post',
        data: tlink,
        headers: { Authorization: `Bearer ${window.sessionStorage.getItem('token')}` }
    });
}


// 删除电视剧链接
export function deleteTeleplayLink(id) {
    let sign = sha256(id + 'XpFaEDYkQH').toString().substring(0, 15);
    return httpRequest({
        baseURL: '/admin',
        url: `/tlink/${id}?time=${Math.round(new Date().getTime() / 1000)}&sign=${sign}`,
        method: 'delete',
        headers: { Authorization: `Bearer ${window.sessionStorage.getItem('token')}` }
    });
}


// 编辑电视剧链接
export function editTeleplayLink(id, tlink) {
    tlink['time'] = Math.round(new Date().getTime() / 1000);
    let params = `${tlink.name}${tlink.url}XpFaEDYkQH`;
    tlink['sign'] = sha256(params).toString().substring(0, 15);
    return httpRequest({
        baseURL: '/admin',
        url: `/tlink/${id}`,
        method: 'put',
        data: tlink,
        headers: { Authorization: `Bearer ${window.sessionStorage.getItem('token')}` }
    });
}
